Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add measure command #124

Merged
merged 1 commit into from
Dec 20, 2020
Merged

Add measure command #124

merged 1 commit into from
Dec 20, 2020

Conversation

aycabta
Copy link
Member

@aycabta aycabta commented Aug 14, 2020

You can use measure command to check performance in IRB like below:

irb(main):001:0> 3
=> 3
irb(main):002:0> measure
TIME is added.
=> nil
irb(main):003:0> 3
processing time: 0.000058s
=> 3
irb(main):004:0> measure :off
=> nil
irb(main):005:0> 3
=> 3

You can set measure :on by IRB.conf[:MEASURE] = true in .irbrc, and, also, set custom performance check method:

IRB.conf[:MEASURE_PROC][:CUSTOM] = proc { |context, code, line_no, &block|
  time = Time.now
  result = block.()
  now = Time.now
  puts 'custom processing time: %fs' % (Time.now - time) if IRB.conf[:MEASURE]
  result
}

@ko1
Copy link
Contributor

ko1 commented Aug 14, 2020

MEASURE_MODE like IRB.conf[:PROMPT_MODE] = :DEFAULT ? (nil by default disables the measurement)

@ko1
Copy link
Contributor

ko1 commented Aug 14, 2020

or it can be stack-able (measure time, memory, ...) different from prompt.

@aycabta
Copy link
Member Author

aycabta commented Dec 18, 2020

Most of the measurements will affect each other. Also, if IRB makes multiple executions for each measuring, code with side effects will not be measured correctly, and execution time will be longer. Therefore, I don't think the stackable way is possible.

@aycabta aycabta force-pushed the add-measure branch 4 times, most recently from a86eb5b to 0bde35e Compare December 20, 2020 06:41
@aycabta
Copy link
Member Author

aycabta commented Dec 20, 2020

I thought about it again, and I think stackable is possible, so I implemented it.

You can use "measure" command to check performance in IRB like below:

  irb(main):001:0> 3
  => 3
  irb(main):002:0> measure
  TIME is added.
  => nil
  irb(main):003:0> 3
  processing time: 0.000058s
  => 3
  irb(main):004:0> measure :off
  => nil
  irb(main):005:0> 3
  => 3

You can set "measure :on" by "IRB.conf[:MEASURE] = true" in .irbrc, and, also,
set custom performance check method:

  IRB.conf[:MEASURE_PROC][:CUSTOM] = proc { |context, code, line_no, &block|
    time = Time.now
    result = block.()
    now = Time.now
    puts 'custom processing time: %fs' % (Time.now - time) if IRB.conf[:MEASURE]
    result
  }
@aycabta aycabta merged commit ed8e097 into ruby:master Dec 20, 2020
@aycabta aycabta deleted the add-measure branch December 20, 2020 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants